package ventanasYDialogos;

import javax.swing.JOptionPane;

public class VUnirse extends javax.swing.JFrame {

    private String usuario;

    public VUnirse(String usuario) {
        initComponents();
        this.usuario = usuario;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTF_ipServidor = new javax.swing.JTextField();
        jB_aceptar = new javax.swing.JButton();
        jB_cancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TEG CT - Unirse");
        setResizable(false);

        jLabel1.setText("IP Servidor: ");

        jTF_ipServidor.setText("localhost");
        jTF_ipServidor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTF_ipServidorKeyPressed(evt);
            }
        });

        jB_aceptar.setText("Aceptar");
        jB_aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_aceptarActionPerformed(evt);
            }
        });

        jB_cancelar.setText("Cancelar");
        jB_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_cancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTF_ipServidor, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jB_aceptar)
                        .addGap(63, 63, 63)
                        .addComponent(jB_cancelar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTF_ipServidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jB_aceptar)
                    .addComponent(jB_cancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jB_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_cancelarActionPerformed
    VLobby vl = new VLobby(this.usuario);
    vl.setVisible(true);
    vl.setLocationRelativeTo(null);
    this.dispose();
}//GEN-LAST:event_jB_cancelarActionPerformed

private void jB_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_aceptarActionPerformed
    String ipServer = this.jTF_ipServidor.getText();

    if (ipServer.compareToIgnoreCase("") == 0) {
        JOptionPane.showOptionDialog(
                this,
                "Ingrese la dirección del servidor",
                "Atención",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.INFORMATION_MESSAGE,
                null,
                null,
                "aceptar");
    } else {
        VElegirColor vc = new VElegirColor(ipServer, usuario);
        vc.setLocationRelativeTo(null);
        vc.setVisible(true);
        this.dispose();
    }
}//GEN-LAST:event_jB_aceptarActionPerformed

private void jTF_ipServidorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_ipServidorKeyPressed
    if (evt.getKeyCode() == 10) {
        this.jB_aceptarActionPerformed(null);
    }
}//GEN-LAST:event_jTF_ipServidorKeyPressed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_aceptar;
    private javax.swing.JButton jB_cancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTF_ipServidor;
    // End of variables declaration//GEN-END:variables
}